<template>
  <j-modal :title="title" :width="1500" :visible="visible" :maskClosable="false" switchFullscreen @ok="handleOk"
    :okButtonProps="{ class: { 'jee-hidden': false } }" @cancel="handleCancel">
    <scmxjd-form ref="realForm" @ok="submitCallback" :disabled="disableSubmit" />
  </j-modal>
</template>

<script>
import { postAction } from '../../../../../api/manage'

import ScmxjdForm from './ScmxjdForm'

export default {
  name: 'ScmxjdModal',
  components: {
    ScmxjdForm
  },
  data () {
    return {
      title: '',
      width: 2000,
      visible: false,
      disableSubmit: false
    }
  },
  methods: {
    add () {
      this.visible = true
      this.$nextTick(() => {
        this.$refs.realForm.add();
      })
    },
    edit (record) {
      this.visible = true
      this.$nextTick(() => {
        this.$refs.realForm.edit(record);
      })
    },
    close () {
      this.$emit('close');
      this.visible = false;
    },
    handleOk () {
      // this.$refs.realForm.handleOk();
      //提交去顶
      console.log("handleok");
      // if(this.title === '查看报价'){
      //   this.$message.error("已报价，不允许再次报价");
      //   return;
      // }
      let data = this.$refs.realForm.scmxjditemTable.dataSource;
      let ids=[];
      for(let i=0;i<data.length;i++){
        ids.push({
          itemid: data[i].itemid,
          quoprice: data[i].quoprice,
          quoremarks: data[i].quoremarks
        })
      }
        postAction('/rfq.quo/scmquotation/generatequo', { id: ids }).then(res => {
        if (res.success) {
          this.$message.success("生成报价单成功！");
          this.visible = false;
          return;
        } else {
          this.$message.error(res.message);
          return;
        }
      })

    },
    getAllTable() {
      if (!(this.refKeys instanceof Array)) {
        throw this.throwNotArray('refKeys')
      }
      let values = this.refKeys.map(key => getRefPromise(this, key))
      return Promise.all(values)
    },

    submitCallback () {
      // this.$emit('ok');
      // this.visible = false;
      console.log("submitcallback");
    },
    handleCancel () {
      this.close()
    }
  }
}
</script>

<style scoped></style>